import 'package:efood_multivendor/data/api/api_client.dart';
import 'package:efood_multivendor/data/model/body/place_order_body.dart';
import 'package:efood_multivendor/util/app_constants.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/response/response.dart';
import 'package:shared_preferences/shared_preferences.dart';

class OrderRepo {
  final ApiClient apiClient;
  final SharedPreferences sharedPreferences;
  OrderRepo({required this.apiClient, required this.sharedPreferences});

  Future<Response> getRunningOrderList(int offset) async {
    return await apiClient.getData(
        '${AppConstants.RUNNING_ORDER_LIST_URI}?offset=$offset&limit=10');
  }

  Future<Response> getHistoryOrderList(int offset) async {
    return await apiClient.getData(
        '${AppConstants.HISTORY_ORDER_LIST_URI}?offset=$offset&limit=10');
  }

  Future<Response> getOrderDetails(String orderID) async {
    return await apiClient.getData('${AppConstants.ORDER_DETAILS_URI}$orderID');
  }

  Future<Response> cancelOrder(String orderID, String reason) async {
    return await apiClient.postData(AppConstants.ORDER_CANCEL_URI,
        {'_method': 'put', 'order_id': orderID, 'reason': reason});
  }

  Future<Response> trackOrder(String orderID) async {
    return await apiClient.getData('${AppConstants.TRACK_URI}$orderID');
  }

  Future<Response> placeOrder(PlaceOrderBody orderBody) async {
    return await apiClient.postData(
        AppConstants.PLACE_ORDER_URI, orderBody.toJson());
  }

  Future<Response> getDeliveryManData(String orderID) async {
    return await apiClient.getData('${AppConstants.LAST_LOCATION_URI}$orderID');
  }

  Future<Response> switchToCOD(String orderID) async {
    return await apiClient.postData(
        AppConstants.COD_SWITCH_URL, {'_method': 'put', 'order_id': orderID});
  }

  Future<Response?> paymentToken(PaymentBody paymentBody) async {
    return await apiClient.postPayment(
        AppConstants.TELEBIRR_PAYMENT, paymentBody.toJson());
  }

  Future<Response?> unpaidIncompletePayment(
      UnpaidIncompletePaymentBody paymentBody) async {
    return await apiClient.postPayment(
        AppConstants.REISSUE_PAYMENT, paymentBody.toJson());
  }

  Future<Response> fetchUnpaidIncompleteOrders() async {
    return await apiClient.getData(AppConstants.UNPAID_INCOMPLETE_ORDER);
  }
}
